package com.qn.visitor.intercept.handler;


import com.qn.visitor.intercept.IRuleIntercept;
import com.qn.visitor.model.bo.intercept.InterceptRule;
import com.qn.visitor.model.bo.intercept.InterceptSource;
import com.qn.visitor.resources.config.FingerprinUtils;

import java.util.List;
/**
 * qingniu-cloud user source analysis
 *
 * @Author: TXG
 * @Date: 2024/6/11
 * @Version V0.0.2
 */
public class Ja4InterceptHandler extends BaseInterceptHandler {
    public Ja4InterceptHandler(IRuleIntercept intercept){
        super(intercept,null);
    }
    public Ja4InterceptHandler(IRuleIntercept intercept, BaseInterceptHandler handler) {
        super(intercept, handler);
    }

    @Override
    public BaseInterceptHandler intercept(InterceptRule rule, InterceptSource source) {
        Integer state = 0;
        if (rule.getJa4Blacklist() != null && !rule.getJa4Blacklist().isEmpty()) {
            state = execute(source.getJa4(), rule.getJa4Blacklist());
        }
        if (isSuccess(state)) {
            return this;
        } else if (handler != null) {
            return handler.intercept(rule, source);
        }
        return null;
    }

    @Override
    public Integer execute(String atom, List<String> rules) {

        return intercept.execute(atom, rules);
    }

    @Override
    public String getInterceptName() {
        return FingerprinUtils.JA4;
    }
}
